package com.youan.pangu.core.mvc.interceptor;

import com.youan.pangu.base.bean.GlobalValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 打印请求的参数信息
 */
public class ShowRequestParamtersHandlerInterceptor extends HandlerInterceptorAdapter {
    private Logger logger = LoggerFactory.getLogger(GlobalValue.LOOGER_NAME);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if(logger.isDebugEnabled()) {
            Map<String, String[]> allParamterMap = request.getParameterMap();
            allParamterMap.entrySet().forEach(item -> {
                logger.debug("{} ====== {}", item.getKey(), item.getValue());
            });
        }
        return super.preHandle(request, response, handler);
    }
}
